import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import axios from 'axios'

export const coffeeThunk = createAsyncThunk(
  'getCoffee',
  async (args, ThunkApi) => {
    let res = await axios.get('/coffee.json')
    return res.data
  }
)

const coffeeSlice = createSlice({
  name: 'coffee',
  initialState: {
    category: [],
    goods: []
  },
  extraReducers: {
    [coffeeThunk.fulfilled]: (state, { payload }) => {
      state.category = payload.category
      state.goods = payload.goods
    }
  }
})

export default coffeeSlice.reducer
